package cn.tedu.mm.basic.controller;

import cn.tedu.mm.basic.pojo.vo.ListAnnouncementVO;
import cn.tedu.mm.basic.service.IAnnouncementService;
import cn.tedu.mm.common.pojo.vo.PageData;
import cn.tedu.mm.common.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("/announcements")
@Slf4j
@Api(tags = "01. 公告列表")
@Validated
public class AnnouncementController {
    @Value("${tmall.dao.default-query-page-size}")
    private Integer defaultQueryPageSize;
    @Autowired
    private IAnnouncementService announcementService;
    @GetMapping("/list")
    @ApiOperation("分页公共列表")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页码",dataType = "int",defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize",value = "页面内容大小",dataType = "int")
    })
    public JsonResult listAnnouncement(@RequestParam(defaultValue = "1") @Range(min = 1, message = "请选择页码") Integer pageNum, Integer pageSize){
        Integer size = pageSize == null ? defaultQueryPageSize : pageSize;
        final PageData<ListAnnouncementVO> listAnnouncementVOPageData = announcementService.listAnnouncement(pageNum, size);
        return JsonResult.ok(listAnnouncementVOPageData);
    }
}
